#pragma once

/************************************************************************/
/* 
一个后台消息处理线程，对于每个客户端来的消息，轮询分配一个消息到CPUIntensiveThread的消息队列
*/
/************************************************************************/

#include "comm_def.h"
#include "concurrentqueue.h"
#include "ThirdPartyHeads.h"

#include <thread>
#include <memory>

class WebBaseInterface;

class CPUIntensiveThread
{
public:
	static void SClientRequestComeCallback(uS::Async* handle);
public:
	CPUIntensiveThread(WebBaseInterface* pgw);
	~CPUIntensiveThread();
	void WaitJoin();
	void CpuIntensiveProcThread();	//cpu密集型处理(同步)
	void PushJsonRequestMessage(std::shared_ptr<SessionRequestMessageBody> msg);
	void PushPBRequestMessage(std::shared_ptr<SessionRequestMessageBody> msg);

	void MemClientRequestComeCallback();

private:
	std::shared_ptr<std::thread> _cpuThreads;
	moodycamel::ConcurrentQueue<std::shared_ptr<SessionRequestMessageBody>> _recvJsonMessages;
	moodycamel::ConcurrentQueue<std::shared_ptr<SessionRequestMessageBody>> _recvPBMessages;

	WebBaseInterface* _webGateWay = nullptr;
	std::shared_ptr<uS::Async> _asyncClientRequest;
	bool _run = false;
};

